home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0022_Rotate Grahic Image.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  2KB  |  54 lines

  1. {
  2. MIKE BRENNAN
  3.  
  4. > I've been trying For some time to get a Pascal Procedure that can
  5. > SCALE and/or ROTATE Graphic images. if anyone has any idea how to do
  6.  
  7.     Here are a couple of Procedures I made For rotating images, 2D and 3D.  I
  8. basically had to rotate each dot individually, and then form the image by
  9. connecting the specified dots.  Here they are...
  10. }
  11.  
  12. Procedure Rotate(cent1, cent2 : Integer;     { Two centroids For rotation }
  13.                  angle : Real;               { Angle to rotate in degrees }
  14.                  Var coord1, coord2 : Real); { both coordinates to rotate }
  15. Var
  16.   coord1t, coord2t : Real;
  17. begin
  18.   {Set coordinates For temp system}
  19.   coord1t := coord1 - cent1;
  20.   coord2t := coord2 - cent2;
  21.  
  22.   {set new rotated coordinates}
  23.   coord1 := coord1t * cos(angle * pi / 180) - coord2t * sin(angle * pi / 180);
  24.   coord2 := coord1t * sin(angle * pi / 180) + coord2t * cos(angle * pi / 180);
  25.  
  26.   {Change coordinates from temp system}
  27.   coord1 := coord1 + cent1;
  28.   coord2 := coord2 + cent2;
  29. end;
  30.  
  31. Procedure Draw3d(x, y, z : Real; {coordinates} a, b : Real; {View angles}
  32.                  Var newx, newy : Integer); {return coordinates}
  33. Var
  34.   Xd, Yd, Zd : Real;
  35. begin
  36.   Xd := cos(a * pi / 180) * cos(b * pi / 180);
  37.   Yd := cos(b * pi / 180) * sin(a * pi / 180);
  38.   Zd := -sin(b * pi / 180);
  39.   {Set coordinates For X/Y system}
  40.   newx:= round(-z * Xd / Zd + x);
  41.   newy:= round(-z * Yd / Zd + y);
  42. end;
  43.  
  44. {
  45. For the first Procedure, you can rotate an image along any two axes, (ie
  46. X,Y...X,Z...Y,Z).  Simply calculate the centroid For each axe, (the average X
  47. coordinate, or Y or Z), then pass the angle to rotate (use a negative For other
  48. direction) and it will pass back the new rotated coordinates.
  49.  
  50.     The second Procedure is For 3D drawing only. It transforms any 3D dot into
  51. its corresponding position on a 2D plan (ie your screen).  The new coordinates
  52. are returned in the NewX, and NewY. Those are what you would use to plot your
  53. dot on the screen.
  54. }